<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>我正在测试ＰＨＰ功能</title>
</head>
<body>
  <h2>外星人劫持报告Aliens Abducted Me - Report an Abduction</h2>

<?php
  $hisname=$_post['name'];
  /*
  post %kjdsjd]
  dshbcjfow*/
  
  
  $first_name = $_POST['firstname'];
  $last_name = $_POST['lastname'];
  $when_it_happened = $_POST['whenithappened'];
  $how_long = $_POST['howlong'];
  $how_many = $_POST['howmany'];
  $alien_description = $_POST['aliendescription'];
  $what_they_did = $_POST['whattheydid'];
  $fang_spotted = $_POST['fangspotted'];
  $email = $_POST['email'];
  $other = $_POST['other'];
 
 
$servername = "testagain.cjpev2glvtds.us-west-2.rds.amazonaws.com";
$username = "dxh2";
$password = "dxh2mysql";
$con=mysqli_connect($servername,$username,$password);
// Check connection
if (mysqli_connect_errno())
{
echo "dxh2用户 Failed to connect to MySQL: " . mysqli_connect_error();
}

// Create database
$sql="CREATE DATABASE dxhdb2";
if (mysqli_query($con,$sql))
{
echo "Database dxhdb2 created successfully" . "<br />";
}
else
{
echo "Error creating database: " . mysqli_error($con) . "<br />";
}
//$dbname="dxhdb";
/*mysql_close($conn);
// 连接到mysql instance服务器
$conn = new mysqli();
// 检测连接
if (!$conn)
  {
  die("Fail connection to SQL !!!!"  . mysql_error()) . " <br /> ";
  } 
  else
  {
   echo 'SQL server C connected: '  . "<br />";
   }*/
// 取得权限时
//$rootpassword="tamadiaws";
/*$connroot=new mysqli("localhost","root","tamadiaws");
if (!$connroot)
  {
  die('SQL server Could not connect: ' . mysql_error());
  } 
  else
  {
   echo "root privilege accessed! SQL server connected!!!!" . " <br /> ";
   
*/
/* $sql = 'CREATE Database dxhdb2';
    $retval = mysql_query( $sql, $conn );
    if(! $retval )
    {
      die('Could not create database: ' . mysql_error());
    }
    echo "Database dxhdb2 created successfully\n";
  */
//选择数据库
//$con=mysqli_connect($servername,root,"tamadimysql");
// Check connection
/*if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error() . "<br />";
} */

$db=mysql_select_db("dxhdb",$con);
/*$conn=mysqli_connect($servername,root);
if ($conn->connect_error) {
    die("**root用户**Error connecting to MySQL server:" . $conn->connect_error);
  }
  echo "**root用户**server connected successful"."<br />";
  
$db=mysql_select_db( "dxhdb2",$conn);
if (mysqli_query($conn,$db))
{
echo " dxhdb2 selected successfully" . "<br />";
}
else
{
echo "Error dxhdb2 selected : " . mysqli_error($db) . "<br />";
}*/

// Create table
$sql="CREATE TABLE aliens_abduction(
  first_name varchar(30),
  last_name varchar(30),
  when_it_happened varchar(30),
  how_long varchar(3),
  how_many varchar(30),
  alien_description varchar(100),
  what_they_did varchar(100),
  fang_spotted varchar(10),
  other varchar(100),
  email varchar(50))";

// Execute query
if (mysqli_query($con,$sql))
{
echo "表创建成功！" . "<br />";
}
else
{
echo "！创建表失败了－ " . mysqli_error($con,$sql) . $db . "<br />";
};
//mysql_close($conn);

//$sql="INSERT INTO aliens_abduction (first_name, last_name, when_it_happened, how_long,how_many, alien_description, what_they_did, fang_spotted, other, email) VALUES ('$first_name','$last_name','$when_it_happened','$how_long','$how_many','$alien_description','$what_they_did','$fang_spotted','$other','$email')";
//$servername = "dengtest2.cjpev2glvtds.us-west-2.rds.amazonaws.com";
//$username = "dxh";
//$password = "homenumber123";
//$dbname="dxhdb";
//$conn = new mysqli($servername, $username, $password,$dbname);
//mysql_select_db("dxhdb", $conn);
$sqlinsert=mysql_query("INSERT INTO  aliens_abduction (first_name, last_name, when_it_happened, how_long,how_many, alien_description, what_they_did, fang_spotted, other, email) VALUES ('$first_name','$last_name','$when_it_happened','$how_long','$how_many','$alien_description','$what_they_did','$fang_spotted','$other','$email')");

if (!mysql_query($conn,$sqlinsert))
  {
  die('写入数据库Error: ' . mysql_error() . "<br />");
  echo '$sqlinsert' . "<br />";
  }
  else
  {
      echo "1 record added" . "<br />";
   }

//mysql_close($conn);
   
if mysqli_query($conn,$sql){
  echo"记录添加成功！new record created successfully!"."<br />";
  }else{
  echo "记录添加失败！Error querying database:".$query."<br>".mysqli_error($conn);
  } 
 mysql_close($con); 
echo "Thanks for submitting the form"."<br />";
  
  echo "You ++were abducted " . $when_it_happened . "<br />";
  echo " and were gone for " . $how_long . "<br />";
  echo "Number of aliens: " . $how_many . "<br />";
  echo "Describe them: " . $alien_description . "<br />";
  echo "The aliens did this: " . $what_they_did . "<br />";
  echo "Was Fang there? " . $fang_spotted . "<br />";
  echo "Other comments: " . $other . "<br />";
  echo "Your email address is " . $email;
    
   ?>
   </body>
</html>